package com.lanhao.aot.bean.scope;

import org.springframework.stereotype.Component;

@Component
public class SingletonBeanScopeService {
	// ThreadLocal局部变量
	private ThreadLocal<String> threadLocalVariable = new ThreadLocal<String>();
	// 普通局部变量
	private String localVariable = null;

	// 设置普通局部变量的值
	public String setLocalVariable() {
		String threadName = Thread.currentThread().getName();
		String value = "这是线程" + threadName + "为我赋的值";
		localVariable = value;
		return localVariable;
	}

	// 设置ThreadLocal局部变量的值
	public String setThreadLocalVariable() {
		String threadName = Thread.currentThread().getName();
		String value = "这是线程" + threadName + "为我赋的值";
		threadLocalVariable.set(value);
		return value;
	}

	// 获取普通局部变量的值
	public String getLocalVariable() {
		String threadName = Thread.currentThread().getName();
		String respAnswer = "当前线程是" + threadName + ",获取到的普通局部变量值为：" + localVariable;
		return respAnswer;
	}

	// 获取ThreadLocal局部变量的值
	public String getThreadLocalVariable() {
		String threadName = Thread.currentThread().getName();
		String respAnswer = "当前线程是" + threadName + ",获取到的ThreadLocal变量值为：" + threadLocalVariable.get();
		return respAnswer;
	}
}
